package com.yanqu.road.server.cmd.beauty;

import com.yanqu.road.entity.player.UserBeauty;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.beauty.BeautyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.pb.BeautyPb;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = BeautyProto.BeautyPeerlessBindPatronsReqMsg.class, respMsg = BeautyProto.BeautyPromotionRespMsg.class)
@Cmd(code = Protocol.S_BEAUTY_BIND_PATRONS, desc = "美女无双绑定门客")
public class BeautyPeerlessBindPatronsCmd extends AbstractCommand {
    private int beautyId;
    private int position;
    private int patronsId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BeautyProto.BeautyPeerlessBindPatronsReqMsg req = BeautyProto.BeautyPeerlessBindPatronsReqMsg.parseFrom(packet.getBytes());
        beautyId = req.getBeautyId();
        position = req.getPosition();
        patronsId = req.getPatronsId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(BeautyModule.class).peerlessBindPatrons(beautyId, position, patronsId);
    }

    @Override
    public void sendData(GamePlayer player) {
        BeautyProto.BeautyPromotionRespMsg.Builder respMsg = BeautyProto.BeautyPromotionRespMsg.newBuilder();
        respMsg.setRet(ret);
        if (0 == ret) {
            UserBeauty userBeauty = player.getModule(BeautyModule.class).getUserBeauty(beautyId);
            BeautyProto.BeautyTempMsg.Builder beautyMsg = BeautyPb.parseBeautyTempMsg(userBeauty);
            if (null != beautyMsg) {
                respMsg.setBeauty(beautyMsg);
            }
        }
        player.sendPacket(Protocol.U_BEAUTY_BIND_PATRONS, respMsg);
    }
}
